﻿#region using
using System;
using System.Collections;
using System.Collections.Generic;
using Janksen.Mapping.EntityExtend;
#endregion

namespace Janksen.Mapping
{
    /// <summary>
    /// 实体扩展相关类
    /// </summary>
    public class EntityExtendHelper
    {
        #region 私有成员
        private static readonly Hashtable instanceCache = Hashtable.Synchronized(new Hashtable());
        #endregion

        #region 获取扩展实体的实例
        /// <summary>
        /// 获取扩展实体的实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IEntityExtend GetInstance<T>()
        {
            IEntityExtend instance = null;

            string hashKey = typeof(T).FullName;

            if (instanceCache.ContainsKey(hashKey))
            {
                instance = instanceCache[hashKey] as IEntityExtend;
            }
            else
            {
                instance = GenEntityExtend.GenExtendClass<T>();
                instanceCache.Add(hashKey, instance);
            }

            return instance;
        }
        #endregion
    }
}
